import player from "./Game/Player";
const {ccclass, property} = cc._decorator;

@ccclass
export default class Skill_consume_MP extends cc.Component {

    @property({displayName: "每使用一次消耗多少蓝", tooltip: "每使用一次消耗多少蓝", type: cc.Float})
    how: number = 0;

    // player节点上的player脚本
    player: player = null;

    // 自身技能按钮
    btn: cc.Button = null;

    onLoad () {
        // 获取Player脚本
        this.player = cc.find("Canvas/player").getComponent("Player");
        // 获取自身技能按钮
        this.btn = this.node.getComponent(cc.Button);
    }

    onbtn () {
        let self = this;

        // 减少魔法值
        self.player.reduce_MP(self.how);
    }


    update () {
        // 获取当前魔法值
        let MP = this.player.cur_MP

        // 如果魔法值不够，禁用按钮
        // 如果魔法够，启用按钮
        if (MP < this.how) {
            this.btn.interactable = false;
        } else {
            this.btn.interactable = true;
        }
    }



}
